-- 协议管理器，将协议组织成 proto_name <-> proto_id 对应映射
local M = {}
function M:new()
    local obj = {
        proto_ids = {}, -- proto_name -> proto_id
        proto_names = {} -- proto_id -> proto_name
    }

    self.__index = self
    setmetatable(obj, self)
    return obj
end

function M:name(proto_id)
    return self.proto_names[proto_id]
end

function M:id(proto_name)
    return self.proto_ids[proto_name]
end

function M:register(id, name)
    assert(not self.proto_ids[name], "duplicate proto name: " .. tostring(name))
    assert(not self.proto_names[id], "duplicate proto id: " .. tostring(id))

    self.proto_ids[name] = id
    self.proto_names[id] = name
end

return M
